/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.dataacesslayer;

import mnstudent.datatranferobject.PriorityObjectDetailDTO;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author 11520_000
 */
public class PriorityObjectDetailDAL {
    
     //<editor-fold defaultstate="collapsed" desc="Attributes">
    private PriorityObjectDetailDTO m_PriorityObjectDetailDTO;
    private DataExecuteUseStoreProcedure m_DataExecute;
    private String  m_sqlCmd;
    
    //</editor-fold>
    
    public PriorityObjectDetailDAL() {
        this.m_PriorityObjectDetailDTO = new PriorityObjectDetailDTO();
        this.m_DataExecute = new DataExecuteUseStoreProcedure();    
        this.m_sqlCmd = "";
    }

    /**
     * Ham lay tat ca cac Chi Tiet Doi tuong
     *
     * @return boolean
     */
    public ResultSet getAllPrioritySubDetail() {
        
        try
        {
            m_sqlCmd = "{Call GetAllPrioritySubjectDetailFromDatabase}";
            ResultSet _rsData = this.m_DataExecute.getDataFromDatabase(m_sqlCmd,null);
            return _rsData;
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    
    public ResultSet getPrioritySubDetailByIdStudent(String _id) {        
        try {
            m_sqlCmd = "{Call GetPrioritySubjectDetailByIdStudent(?)}";
            String[] arrId = {_id};
            return this.m_DataExecute.getDataFromDatabase(m_sqlCmd, arrId);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    /**
     * Ham insert mot chi tiết đối đượng xuống database
     * @param _subDetail
     * @return 
     */
    public boolean insertPrioritySubDetail(PriorityObjectDetailDTO _subDetail)
    {
       try {
           m_sqlCmd = "{Call InsertPrioritySubDetailToDatabase(?,?)}";
           String[] arrStr = {_subDetail.getStudentID(), _subDetail.getPrioritySubjectID()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    public boolean insertArrayPrioritySubDetail(ArrayList<PriorityObjectDetailDTO> _arrSubDetail)
    {
        boolean rs = false;
       try {
           for(PriorityObjectDetailDTO i: _arrSubDetail){  
               if(insertPrioritySubDetail(i))
                   rs = true;
               else
                   rs = false;
           }
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return rs;
    }
    
    public boolean deletePrioritySubDetailFromDatabase(String _subDetailID)
    {
        try {
           m_sqlCmd = "{Call DeletePrioritySubDetailFromDatabase(?)}";
           String[] arrStr = { _subDetailID};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd, arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
}
